﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ZOVNP.Model.Abstracts;

namespace ZOVNP.Engine
{
    [DomainObject(typeof(IOrderPart))]
    public partial class OrderPart : IOrderPart
    {
        private IDomainReference<IOrderPartHelp> _orderPartHelpLocker;
        private IDomainReference<IOrder> _orderLocker;
        private IDomainCollection<IOrderItem> _orderItemsLocker;

        public OrderPart()
        {
            _orderPartHelpLocker = new SmartReference<OrderPart, OrderPartHelp, IOrderPartHelp>(this, OrderPartHelpReference,
                                                                                                it => it._OrderPartHelpID);
            _orderLocker = new SmartReference<OrderPart, Order, IOrder>(this, OrderReference, it => it.OrderID);
            _orderItemsLocker = new SmartCollection<OrderItem, IOrderItem>(this, OrderItems);
        }

        IDomainReference<IOrderPartHelp> IOrderPart.OrderPartHelpReference
        {
            get { return _orderPartHelpLocker; }
        }

        IOrderPartHelp IOrderPart.OrderPartHelp
        {
            get
            {
                return _orderPartHelpLocker.Value;
            }
            set
            {
                _orderPartHelpLocker.Value = value;
            }
        }

        IDomainReference<IOrder> IOrderPart.OrderReference
        {
            get { return _orderLocker; }
        }

        IOrder IOrderPart.Order
        {
            get
            {
                return _orderLocker.Value;
            }
            set
            {
                _orderLocker.Value = value;
            }
        }

        IDomainCollection<IOrderItem> IOrderPart.OrderItems
        {
            get { return _orderItemsLocker; }
        }
    }
}
